<?php
/*
 *  supplier 供货商添加类
 *
 *  @param $c 一般是类名
 *  @param $a 一般是方法名
 */
class commonInfo extends goodsSaler {

    private $tab = array( 'logistics' => '物流信息管理','size'=>'尺码信息');
    private $clothType = array( 'T恤', '连衣裙', '裤子','上衣','半身裙','短裤');
    private $clothTableArray = array('height'=>'身高','age'=>'年龄','clothSize'=>'衣长',
                                       'dressSize'=>'裙长','trousersSize'=>'裤长',
                                       'sleeveSize'=>'袖长','waistSize'=>'腰宽' );
    private $clothSizeRef = array(
                                     0=>array('height','age','clothSize','sleeveSize','waistSize'),
                                     1=>array('height','age','dressSize','sleeveSize','waistSize'),
                                     2=>array('height','age','trousersSize','sleeveSize','waistSize'),
                                     3=>array('height','age','clothSize','sleeveSize','waistSize'),
                                     4=>array('height','age','dressSize','sleeveSize','waistSize'),
                                     5=>array('height','age','trousersSize','sleeveSize','waistSize')
                                  );







    public function index( $c, $a ) {
        $type = G( 'type', 'size' );
        $method = "{$a}_{$type}";
        $this->$method( $c, $a, $type );
    }

    public function index_logistics( $c, $a ) {
        $type = G( 'type', 'logistics' );
        include $this->display( $c );
    }

    public function index_size( $c, $a ) {
        $type = G( 'type', 'size' );
        include $this->display( $c );
    }

    public function  lookStdSize($c,$a)
    {
        $type = G( 'type', 'size' );
        $this->table = 'refClothSize';

        $key = G('key1',0);
        $arrayfld =$this->clothSizeRef[$key];

        foreach($arrayfld  as $k=>$v)
        {
            $title[$k] =  $this->clothTableArray[ $this->clothSizeRef[$key][$k]];
        }

        $stringArrayfld = implode(',',$arrayfld);

        $result = $this->findAll(null,null,$stringArrayfld);

        include $this->display( $c );
    }




    public function addLogistic($c,$a,$args)
    {
        include $this->display( $c );
    }


    public function addSize($c,$a,$args)
    {
        include $this->display( $c );
    }




    public function edit( $c, $a ) {
        if ( !$id = intval( G( 'id' ) ) ) {
            $this->error();
            exit;
        }

        $this->table = ''; // 数据库表名
        $result = $this->find( array( 'id' => $id ) ); // 查找数据
        include $this->display( $c ); // 加载模板
    }

    public function add( $c, $a ) {
        include $this->display( $c );
    }



    public function saveLogistic($c,$a,$args)
    {
        foreach ( $_POST as $key => $val ) {
            $rows[ $key ] = htmlspecialchars( trim( $val ) );
        }

        /**zouhong-edit**/
       // $rows['companyNo'] = 0;
        /**zouhong-edit-end**/


        # 注意 表单字段必须跟数据库表字段名一样
        $this->table = 'logistic'; // 数据库表名

         $msg = $this->create( $rows ) ? 'success' : 'failed';                         // 添加供货商

        exit( $msg );
    }

    public function saveSize($c,$a,$args)
    {

        foreach ( $_POST as $key => $val ) {
            $rows[ $key ] = htmlspecialchars( trim( $val ) );
        }

        /**zouhong-edit**/
        //$rows['id'] = 0;
        /**zouhong-edit-end**/

        $this->table = 'clothSize'; // 数据库表名
        # 注意 表单字段必须跟数据库表字段名一样
        $msg = $this->create( $rows );

         //$msg = $this->create( $rows ) ? 'success' : 'failed';                         // 添加供货商

       // exit( $msg );
    }


    # 更新附件
    private function updateAttachment( $id, $c ) {
        $attach = $_POST[ 'attach' ][ 'id' ];
        if ( !$attach ) {
            return false;
        }
        $attach = rtrim( $attach, "," );
        $this->table = "attachment";
        $this->update( "id in ({$attach})", array( 'aid' => $id, 'model' => strtolower( $c ) ) );
        return true;
    }


    public function save() {
        # 获取表单数据
        foreach ( $_POST as $key => $val ) {
            $rows[ $key ] = htmlspecialchars( trim( $val ) );
        }

        # 注意 表单字段必须跟数据库表字段名一样
        $this->table = ''; // 数据库表名
        if ( $id = intval( G( "id" ) ) ) {
            $msg = $this->update( array( 'id' => $id ), $rows ) ? 'success' : 'failed';  //更新供货商
        } else {
            $msg = $this->create( $rows ) ? 'success' : 'failed';                         // 添加供货商
        }
        exit( $msg );
    }
}